<template>
  <div class="dialog">
    <el-dialog title="药品详情" :visible.sync="showDialog" width="65%" top="0" :close-on-click-modal="false" @close="cancel">

      <el-row :gutter="15">
        <el-table ref="EpidemicPreventionDetailsList" :data="EpidemicPreventionDetailsList" tooltip-effect="dark"
          highlight-current-row border stripe class="EpidemicPreventionDetailsList">
          <el-table-column type="index" label="序号" width="50" />
          <el-table-column label="药品名称" prop="materialName" align="center" min-width="120">
          </el-table-column>
          <el-table-column label="用药量" prop="num" align="center" min-width="120">
            <template slot-scope="scope">
              <span>{{ scope.row.num + materialObj[scope.row.materialId].unit }}</span>
            </template>
          </el-table-column>
          <el-table-column label="数量"  align="center" min-width="120">
            <template slot-scope="scope">
              <span>{{ scope.row.num / materialObj[scope.row.materialId].ratioNum + materialObj[scope.row.materialId].aUnit }}</span>
            </template>
          </el-table-column>
          <!-- <el-table-column label="转入数量" prop="num" min-width="95" >
          </el-table-column>
          <el-table-column label="转入重量" prop="weight" min-width="95">
          </el-table-column> -->
          <!-- <el-table-column label="操作" min-width="80">
            <template slot-scope="scope">
              <el-button
                v-if="nowChanceStau === 'edit'"
                type="text"
                style="color:red;text-decoration: underline;"
                size="small"
                @click.native.prevent="editRow(scope.$index,scope.row)"
              >提交修改</el-button>
              <el-button
                v-if="nowChanceStau === 'add'"
                type="text"
                style="color:red;text-decoration: underline;"
                size="small"
                @click.native.prevent="deleteRow(scope.$index, rightTableData)"
              >删除</el-button>
            </template>
          </el-table-column> -->
          <template slot="empty">
            <div>暂无数据</div>
          </template>
        </el-table>
      </el-row>
      <!-- <div slot="footer" class="dialog-footer">
        <el-button class="cancelbtn" @click="cancel()">取 消</el-button>
        <el-button type="primary" class="savebtn" @click="save('ruleForm')">保 存</el-button>
      </div> -->
    </el-dialog>
  </div>
</template>

<script>
import EpidemicPreventionDetailsApi from "@/api/health-management/epidemic-prevention-details/index";
import { mapGetters } from "vuex";
import { mymixin } from "@/utils/mixin";
import store from "@/store";
export default {
  name: "",
  components: {},
  mixins: [mymixin],
  props: {
    show: {
      type: Boolean,
      default: false,
    },
    completeInfoObject: {
      type: [Object],
      default: () => {
        return {};
      },
    },
  },
  data() {
    return {
      // rightTableData:[],
      specificationList: [],
      currentBatchId: 1,
      EpidemicPreventionDetailsList: [],
      showDialog: this.show
    };
  },
  computed: {
    ...mapGetters({
      judgePermission: "permission/judgePermission",
    }),
    materialObj() {
      return store.state.basicData.material;
    }
  },
  watch: {
    show(v) {
      this.showDialog = v;
    },
    completeInfoObject(v) {
      this.queryTransferDetail(v.epidemicPreventionId)
    },
  },
  created() { },
  mounted() {
  },
  methods: {
    queryTransferDetail(e) {
      EpidemicPreventionDetailsApi.queryByCondition({ epidemicPreventionId: e }).then(res => {
        this.EpidemicPreventionDetailsList = res.data
        console.log(this.EpidemicPreventionDetailsList);
      })
      // EpidemicPreventionDetailsApi.queryByTransferSeparatePondId({transferSeparatePondId:e}).then(res=>{
      //   this.EpidemicPreventionDetailsList = res.data
      // })
    },
    // 修改一行数据
    editRow(index, rows) {
      let params = {
        inputPondDetailId: rows.inputPondDetailId,
        specificationId: rows.specificationId,
        inputNum: rows.inputNum,
        inputWeight: rows.inputWeight,
      }
      EpidemicPreventionDetailsApi.edit(params).then(res => {
        if (res.success === true) {
          this.$message.success("修改成功！");
        } else {
          this.$message.error(res.message);
        }
      })
    },
    // 删除一行数据
    deleteRow(index, rows) {
      console.log(index, rows);
      this.$confirm("此操作将永久删除该项, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        
      }).then(() => {
        let params = {
          id: rows.inputPondDetailId,
        }
        EpidemicPreventionDetailsApi.delById(params).then(res => {
          if (res.success === true) {
            this.$message.success("删除成功！");
            this.EpidemicPreventionDetailsList.splice(index, 1);
          } else {
            this.$message.error(res.message);
          }
        })
      }).catch(() => {
        this.$message({
          type: "info",
          message: "已取消删除"
        });
      });
    },
    changeCurrentPage(currentPage) {
      this.currentPage = currentPage;
      this.queryPageList();
    },
    close() {
      this.$emit("closeDialog");
    },
    cancel() {
      this.$emit("cancelDialog");
    },
  },
};
</script>

<style lang="scss" scoped>
.pagination {
  position: absolute;
  right: 0px;
  bottom: -40px;
}

.el-table {
  position: relative;
}

::v-deep .el-dialog__body {
  padding: 30px 20px 50px 20px;
}
</style>
